const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const config = require('./config.js')
const app = config.persional?config.wx.appname:config.wx.wmpname+'_'+config.wx.appname
const merge = require('webpack-merge')
const webpackDevConfig = require('./webpack.dev.config.js')
module.exports = merge(webpackDevConfig, {
    entry: {
        index: path.resolve('src', app, 'index.ts'),
        vendor:['axios','@tweenjs/tween.js']
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: '富力公主湾-教育主题',
            filename: 'index.html',
            template: 'html-withimg-loader!' + path.resolve(__dirname, 'src', app, 'index.html'),
            path: path.resolve(__dirname, 'dist', app),
        }),
        new webpack.ProvidePlugin({//遇到$,jQuery,window.jQuery,window.$四个未声明的变量时，会自动调用require('jquery')，如何带入到对应的变量中，如果是一些没有适配cmd/amd规范的JS模块，没法使用这个方法来引入
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            'window.$': 'jquery'
        }),
    ],
    externals: {//将某个全局变量“伪装”成某个js模块的exports
        DS: 'DS',
        wx: 'wx',
        createjs: 'createjs',
        videojs:'videojs'
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    {loader: 'style-loader'},
                    {loader: 'css-loader'},
                ]
            },
            {
                test: /\.(png|jpe?g|gif|ico)(\?\S*)?$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 8192,
                        useRelativePath: true,
                        context: path.resolve(__dirname, 'dist', app),
                        name: '[name].[ext]'
                    }
                }
                ]
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2|mp3|mp4)(\?\S*)?$/,
                use: [{
                    loader: 'file-loader',
                    options: {
                        useRelativePath: true,
                        context: path.resolve(__dirname, 'dist', app),
                        name: '[name].[ext]'
                    }
                }]
            },
            {
                test: /\.js$/,
                exclude: /(node_modules)/,
                use: [{
                    loader: 'babel-loader',
                    query: {
                        presets: ['es2015']
                    }
                }]
            },
            {
                test: /\.ts$/,
                loader:'ts-loader'
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                // base1: require.resolve('jquery'),  // 此loader配置项的目标是NPM中的jquery
                // loader: 'expose-loader?$!expose-loader?jQuery', // 先把jQuery对象声明成为全局变量`jQuery`，再通过管道进一步又声明成为全局变量`$`
            }
        ],
    }
})